from django.db import models

# Create your models here.
from datetime import datetime


class User(models.Model):
    # 定义类的属性
    # models.Model中Django中已定义好增删改查操作了。
    # 以下每个字段，必须对应数据表中的字段
    id = models.SmallIntegerField("ID",primary_key=True)
    username = models.CharField("用户姓名",max_length=16)
    age = models.SmallIntegerField("用户年龄",)
    nickname = models.CharField("用户昵称",max_length=16)
    userpwd = models.CharField("用户密码",max_length=16)
    status = models.SmallIntegerField("用户状态", default=1)  # 1有效，9无效
    createtime = models.DateTimeField(default=datetime.now)

    def toDict(self):
        return {'id':self.id,'username':self.username,'nickname':self.nickname,'userpwd':self.userpwd,'age':self.age,'status':self.status,'createtime':str(self.createtime)}

    # 定义默认输出格式
    def __str__(self):
        return "%d:%s:%d:%s:%s:%d:%s" % (self.id, self.username, self.age, self.nickname, self.userpwd, self.status,self.createtime)

    # 自定义对应的表名
    class Meta:
        db_table = "user"
        verbose_name = "用户信息"
        # verbose_name_plural = "用户信息管理"